<html>
<head>
<#assign basePath=request.contextPath>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>后台管理系统</title>
    <link href="${basePath}/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link href="${basePath}/bootstrap/css/font-awesome.min.css" rel="stylesheet">
    <link href="${basePath}/bootstrap/css/form.lzy.css" rel="stylesheet">
    <link href="${basePath}/bootstrap/css/good.lzy.css" rel="stylesheet">
    <link href="${basePath}/bootstrap/plugin/bootstrap-datetimepicker/bootstrap-datetimepicker.min.css"
          rel="stylesheet">
    <style>
        #file {
            display: inline-block;
        }

        #fileValue{
            width: 0;
            height: 0;
            opacity: 0;
            font-size: 0;
        }

    </style>
</head>
<body>

<div class="content-header">
    <h5>
        卡券宝 &gt; 文字管理 &gt; <strong>购买说明</strong>
    </h5>
</div>

<div class="panel panel-lzy">
    <div class="panel-body">
        <h5 class="tips-lzy">操作提示</h5>
        <ul class="tips-list-lzy">
            <li><span>◆&nbsp;<span>标识“<font color="red">*</font>”的选项为必填项，其余为选填项。</span></span></li>
        </ul>
    </div>
</div>

<div id="page-wrapper">
    <div class="panel panel-f5">
        <div class="panel-body row">
            <input type="hidden" id="_ctx" value="${basePath}"/>
            <form id="Form" class="form-horizontal" method="post">
                <div class="form-group">
                    <span class="control-label col-sm-2 col-xs-4 detail-span"><span class="text-red">*</span>&nbsp;上传购买说明文档：</span>
                    <div class="col-sm-9 col-xs-8">
                    <#if (dto.office)??>
                        <input type="text" id="fileText" class="form-control" size="50" value="${dto.office!}" readonly />
                        <input type="file" data-action="office" data-image="word" onchange="uploadFile(this,'.docx',10)" id="file">
                        <input type="text" id="fileValue" name="office" value="${dto.office!}">
                    <#else>
                        <input type="text" id="fileText" class="form-control" size="50" value="" readonly style="display: none" />
                        <input type="file" data-action="office" data-image="word" onchange="uploadFile(this,'.docx',10)" id="file">
                        <input type="text" id="fileValue" name="office" value="" class="file">
                    </#if>
                        <br/><span class="text-warning">请上传购买说明内容，请确保您上传的内容正确</span>
                    </div>
                </div>
                <br>
                <div class="form-group">
                    <span class="control-label col-sm-4 col-xs-4"></span>
                    <div class="col-sm-8 col-xs-8">
                    <#if dto??>
                        <button type="button" class="btn btn-success" onclick="submitFormEdit();"><i
                                class="fa fa-check"></i>提交
                        </button>
                    <#else>
                        <button type="button" class="btn btn-success" onclick="submitForm();"><i
                                class="fa fa-check"></i> 提交
                        </button>
                    </#if>
                        <button type="button" class="btn btn-info" onclick="goBack()"><i class="fa fa-close"></i>返回
                        </button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>


<script src="${basePath}/bootstrap/js/jquery.js" type="text/javascript"></script>
<script src="${basePath}/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
<script src="${basePath}/bootstrap/plugin/layer/layer.js" type="text/javascript"></script>
<script type="text/javascript"
        src="https://cdn.bootcss.com/bootstrap-validator/0.5.3/js/bootstrapValidator.min.js"></script>
<script type="text/javascript" src="https://cdn.bootcss.com/bootstrap-validator/0.5.3/js/language/zh_CN.js"></script>
<script type="text/javascript">
    $(window).bootstrapValidator || document.write('<script src="${basePath}/bootstrap/js/bootstrapValidator.min.js"><\/script>' +
            '<script src="${basePath}/bootstrap/js/bootstrapValidator-zh_CN.js"><\/script>');
</script>
<script src="${basePath}/bootstrap/js/common.js" type="text/javascript"></script>
<script type="text/javascript"
        src="${basePath}/bootstrap/plugin/bootstrap-datetimepicker/bootstrap-datetimepicker.min.js"></script>
<script type="text/javascript"
        src="${basePath}/bootstrap/plugin/bootstrap-datetimepicker/bootstrap-datetimepicker.zh-CN.js"></script>
<script src="${basePath}/bootstrap/js/campsite.js" type="text/javascript"></script>
<script>

    function goBack() {
        window.location.href = "${basePath}/admin/product/info"
    }
    //新增
    function submitForm() {
        var bsVal = $("#Form").data('bootstrapValidator');
        bsVal.validate();
        if (bsVal.isValid()) {
            $.ajax({
                type: 'POST',
                dataType: 'json',
                url: '${basePath}/admin/product/info/save',
                data: $("#Form").serialize(),
                success: function (data) {
                    if (data.code == '0') {
                        layer.alert('操作成功', {
                            icon: 1
                        }, function () {
                            window.location.href = '${basePath}/admin/product/info';
                        })
                    } else {
                        layer.alert(data.desc, {
                            icon: 5
                        });
                    }
                },
                error: function () {
                    layer.alert('系统错误', {
                        icon: 5
                    });
                }
            });

        }
        else {
            var smallTop = $("small:visible").eq(0).offset().top - 50;
            $("html,body").animate({scrollTop: smallTop}, 300);
        }
    }

    //编辑
    function submitFormEdit() {

        if (!$("#identity-input").is(":checked")) {
            $("#identityId").val("0")
        }

        var bsVal = $("#Form").data('bootstrapValidator');
        bsVal.validate();
        if (bsVal.isValid()) {
            $.ajax({
                type: 'POST',
                dataType: 'json',
                url: '${basePath}/admin/product/info/update',
                data: $("#Form").serialize(),
                success: function (data) {
                    if (data.code == '0') {
                        layer.alert('操作成功', {
                            icon: 1
                        }, function () {
                            window.location.href = '${basePath}/admin/product/info';
                        })
                    } else {
                        layer.alert(data.desc, {
                            icon: 5
                        });
                    }
                },
                error: function () {
                    layer.alert('系统错误', {
                        icon: 5
                    });
                }
            });

        }
        else {
            var smallTop = $("small:visible").eq(0).offset().top - 50;
            $("html,body").animate({scrollTop: smallTop}, 300);
        }
    }

    //表单验证
    $('#Form').bootstrapValidator({
        fields: {
            office: {
                trigger: "change",
                validators: {
                    notEmpty: {
                        message: '请上传文档'
                    }
                }
            }
        }
    });
</script>
</body>
</html>